package com.ys.util;

import java.math.BigDecimal;

/**
 * @Author: fxz
 * @CreateTime: 2024-12-16
 * @Description: FBA工具类
 * @Version: 1.0
 */
public class FbaUtils {
    public static BigDecimal precision(BigDecimal f){
        //根据数字未满5满5,未满10满10
        String s = f.stripTrailingZeros().toPlainString();
        String ff = f.toString();
        int rs = s.indexOf(".");
        if (rs != -1) {
            //取出第一位
            String first = s.substring(0,rs);
            //根据第一位小数5来判断，大于0.5以上进1,小于0.5的为0.5
            first = first + ".5";
            Double fD = Double.parseDouble(String.valueOf(f));
            Double firstD = Double.parseDouble(first);
            if (fD < firstD){
                ff = first;
            } else if(fD > firstD) {
                ff = String.valueOf(Math.round(fD));
            }
        }
        return new BigDecimal(ff);
    }
}
